sprite = codesters.Sprite("knight1", -175, -150)
sprite.set_speed(2)
def park_scene():
stage.set_background("park")
sprite.say("I should hurry to the castle!")
sprite.move_forward(550)
park_scene()
def bridge_scene():
stage.set_background("drawbridge")
sprite.go_to(-175, -150)
sprite.say("I made it!")
stage.wait(2)
bridge_scene()
def battle_scene():
dragon = codesters.Sprite("dragon", 150, -150)
sprite.say("Oh no a dragon!")
sprite.move_forward(300)
dragon.turn_left(360)
dragon.move_down(200)
sprite.say("The path is clear!")
battle_scene()
t = codesters.Teacher()
try:
func = t.find_text('def reward_scene')
tval1 = func[0][1]
except:
func = "DNE"
tval1 = "DNE"
try:
setting = t.find_text('stage')
line = setting[3][0]
tval2 = t.get_indent_at_line(line)
tval3 = setting[3][1]
except:
setting = "DNE"
line = "DNE"
tval2 = "DNE"
tval3 = "DNE"
try:
char = t.find_text('.Sprite')
line = char[2][0]
tval4 = t.get_indent_at_line(line)
tval5 = char[2][1]
except:
char = "DNE"
line = "DNE"
tval4 = "DNE"
tval5 = "DNE"
try:
waits = t.find_function('wait')
line = waits[1][0]
tval6 = t.get_indent_at_line(line)
tval7 = waits[1][1]
except:
line = "DNE"
tval6 = "DNE"
tval7 = "DNE"
try:
say_params = t.find_function('say')
tval8 = say_params[4][1]
tval9 = say_params[4][0]
except:
tval8 = "DNE"
tval9 = "DNE"
t1 = TestObjective()
t1.add_success('def reward_scene():' in tval1, "Great job!")
t1.add_failure('reward_scene' not in tval1, "Did you create a function and name it reward_scene?")
t2 = TestObjective()
t2.add_success(tval2 == 4 and 'castle' in tval3, "Great job!")
t2.add_failure('stage' not in tval3, "Did you put a stage backgound in your function?")
t2.add_failure(tval2 < 4, "Did you indent your background in your function?")
t2.add_failure(tval2 > 4, "It looks like you indented the background too far. It should be nested 4 spaces inside your function.")
t2.add_creative('castle' not in tval3, "It looks like you chose a different background for your function reward_scene(). Creative choice!")
t3 = TestObjective()
t3.add_success(tval4 == 4 and 'wizard' in tval5 and '150, -150' in tval5, "Great job!")
t3.add_failure(tval5 == "DNE", "Did you add a wizard into your reward function?")
t3.add_failure('sprite =' in tval5, "Did you change the name of the sprite to wizard?")
t3.add_failure(tval4 < 4, "Did you indent your wizard inside the reward function?")
t3.add_failure(tval4 > 4, "It looks like you indented your wizard sprite too much. It should be nested 4 spaces inside the reward function.")
t3.add_creative('-150, -150' not in tval5, "Looks like you chose a different position for your wizard. Creative choice!")
t3.add_creative('"wizard"' not in tval5, "Looks like you chose a different sprite to give your reward! Creative choice!")
t4 = TestObjective()
t4.add_success('2' in tval7 and tval6 == 4, "Great job!")
t4.add_failure(tval6 == "DNE", "Did you add a wait command to your reward scene function?")
t4.add_failure(tval6 == 0, "Did you indent your wait command 4 spaces inside the reward scene function?")
t5 = TestObjective()
t5.add_success('you' in tval8 and tval9 == 4, "Great job!")
t5.add_failure(tval8 == "DNE", "Did you add a say command?")
t5.add_failure("am a sprite" in tval8, "Did you change the string in the Say command?")
t5.add_failure(tval9 == 0, "Did you indent the say command inside the function?")
tester = TestManager()
tester.add_test_list([t1, t2, t3, t4, t5])
tester.run_tests()
tester.display_first_feedback()
-
Run Code
-
Activity Submitted!
提交作品
-
下个活动
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)